import { request } from '../../utils/request'
import type { Department, ApiResponse } from '../../types/app.d'

/**
 * 获取部门列表
 */
export const getDeptList = (params?: {
  status?: number
  name?: string
}) => {
  return request.get<ApiResponse<Department[]>>('/system/dept/list', { params })
}

/**
 * 获取部门详情
 */
export const getDeptInfo = (id: string) => {
  return request.get<ApiResponse<Department>>(`/system/dept/${id}`)
}

/**
 * 创建部门
 */
export const createDept = (data: Omit<Department, 'id' | 'createTime' | 'updateTime' | 'children'>) => {
  return request.post<ApiResponse>('/system/dept', data)
}

/**
 * 更新部门
 */
export const updateDept = (id: string, data: Partial<Omit<Department, 'id' | 'createTime' | 'children'>>) => {
  return request.put<ApiResponse>(`/system/dept/${id}`, data)
}

/**
 * 删除部门
 */
export const deleteDept = (id: string) => {
  return request.delete<ApiResponse>(`/system/dept/${id}`)
}

/**
 * 获取部门树结构
 */
export const getDeptTree = (params?: {
  status?: number
}) => {
  return request.get<ApiResponse<Department[]>>('/system/dept/tree', { params })
}